package practice;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class Day18 {
    //最长回文子序列
    //https://www.nowcoder.com/practice/82297b13eebe4a0981dbfa53dfb181fa?tpId=230&tqId=39762&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int len = s.length();
        int[][] dp = new int[len][len];
        int max = 0;
        for (int i = len - 1; i >= 0; i--) {
            dp[i][i] = 1;
            for (int j = i + 1; j < len; j++) {
                if (s.charAt(i) == s.charAt(j)) {
                    dp[i][j] = dp[i + 1][j - 1] + 2;
                } else {
                    dp[i][j] = Math.max(dp[i + 1][j], dp[i][j - 1]);
                }
                max = Math.max(max,dp[i][j]);
            }

        }
        System.out.println(max);
    }

    //设置一个简易计算机（加减乘除）：没有负数
    public int calculate(String s) {
        int i = 0;
        int len = s.length();
        Stack<Integer> stack = new Stack<>();
        //定义一个字符，用来记录每次遇到的运算符
        char ot = '+';
        while(i < len) {
            char ch = s.charAt(i);
            if(ch == ' ') {
                i++;
            }else if(ch >= '0' && ch <= '9') {
                //处理100这种情况
                int tmp = 0;
                while(i < len && s.charAt(i) >= '0' && s.charAt(i) <= '9') {
                    System.out.println(s.charAt(i));
                    System.out.println(tmp);
                    tmp = tmp * 10 + (s.charAt(i) - '0');
                    System.out.println(tmp);
                    i++;
                }
                if(ot == '+') {
                    stack.push(tmp);
                }else if(ot == '-') {
                    stack.push(-tmp);
                }else if(ot == '*') {
                    stack.push(stack.pop()*tmp);
                }else if(ot == '/') {
                    stack.push(stack.pop() / tmp);
                }
            }else {
                ot = s.charAt(i);
                i++;
            }
        }
        int ret = 0;
        while(!stack.isEmpty()) {
            ret += stack.pop();
        }
        return ret;
    }


    private int n;
    private boolean[] vis = new boolean[210];
    public int citys(ArrayList<ArrayList<Integer>> m)
    {
        n = m.size();
        int ret = 0;
        for(int i = 0; i < n; i++)
        {
            if(!vis[i])
            {
                ret++;
                dfs(m, i);
            }
        }
        return ret;
    }
    public void dfs(ArrayList<ArrayList<Integer>> m, int pos) {
        vis[pos] = true;
        for (int i = 0; i < n; i++) {
            if (m.get(pos).get(i) == 1 && !vis[i]) {
                dfs(m, i);
            }
        }
    }

}
